package com.dhj.yygh.controller.api;

import com.dhj.yygh.common.result.MyResult;
import com.dhj.yygh.common.result.Result;
import com.dhj.yygh.model.hosp.Hospital;
import com.dhj.yygh.model.hosp.Schedule;
import com.dhj.yygh.service.DepartmentService;
import com.dhj.yygh.service.HospitalService;
import com.dhj.yygh.service.ScheduleService;
import com.dhj.yygh.vo.hosp.DepartmentVo;
import com.dhj.yygh.vo.hosp.HospitalQueryVo;
import com.dhj.yygh.vo.hosp.ScheduleOrderVo;
import com.dhj.yygh.vo.order.SignInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api(tags = "医院 api 接口")
@RestController
@RequestMapping("/api/hospital")
public class HospitalApiController {
    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @ApiOperation("分页获取医院列表")
    @GetMapping("/getHospitalPage/{page}/{pageCount}")
    public MyResult<Page<Hospital>> getHospitalPage(
            @PathVariable("page") Integer page,
            @PathVariable("pageCount") Integer pageCount,
            HospitalQueryVo hospitalQueryVo) {

        // 切记 page - 1
        Page<Hospital> hospitalPage = hospitalService.selectHospitalPage(page - 1, pageCount, hospitalQueryVo);
        return MyResult.ok(hospitalPage);
    }

    @ApiOperation("根据医院名称做模糊查询")
    @GetMapping("/getHospitalByHosname/{hosname}")
    public MyResult<List<Hospital>> getHospitalByHosname(
            @PathVariable("hosname") String hosname
    ) {
        List<Hospital> hospitalList = hospitalService.getHospitalByHosname(hosname);

        return MyResult.ok(hospitalList);
    }

    @ApiOperation("根据医院编号获取所有的科室信息")
    @GetMapping("/getDepartmentByHoscode/{hoscode}")
    public MyResult<List<DepartmentVo>> getDepartmentByHoscode(
            @PathVariable("hoscode") String hoscode) {

        List<DepartmentVo> departmentInfoByHoscode =
                departmentService.getDepartmentInfoByHoscode(hoscode);
        return MyResult.ok(departmentInfoByHoscode);
    }

    @ApiOperation("根据医院编号获取医院基本信息和预约信息")
    @GetMapping("/getHospitalDetail/{hoscode}")
    public MyResult<Map<String, Object>> getHospitalDetailByHoscode(
            @PathVariable("hoscode") String hoscode) {

        Map<String, Object> resultMap = hospitalService.getHospitalDetailsByHoscode(hoscode);

        return MyResult.ok(resultMap);
    }


    @Autowired
    private ScheduleService scheduleService;

    @ApiOperation(value = "获取可预约排班分页数据")
    @GetMapping("/getBookingScheduleRule/{page}/{limit}/{hoscode}/{depcode}")
    public MyResult<Map<String, Object>> getBookingSchedule(
            @PathVariable Integer page,
            @PathVariable Integer limit,
            @PathVariable String hoscode,
            @PathVariable String depcode) {


        Map<String, Object> resultMap = scheduleService.getBookingScheduleRule(page, limit, hoscode, depcode);
        return MyResult.ok(resultMap);
    }

    @ApiOperation(value = "获取具体的排班数据")
    @GetMapping("/findScheduleList/{hoscode}/{depcode}/{workDate}")
    public MyResult findScheduleList(

            @PathVariable String hoscode,

            @PathVariable String depcode,

            @PathVariable String workDate) {
        return MyResult.ok(scheduleService.getScheduleDetails(hoscode, depcode, workDate));
    }

    @ApiOperation("根据排班 id 获取排班数据")
    @GetMapping("/getScheduleById/{id}")
    public MyResult<Schedule> getScheduleById(
            @PathVariable("id") String id) {
        Schedule schedule = scheduleService.getScheduleById(id);

        return MyResult.ok(schedule);
    }

    @ApiOperation(value = "根据排班 id 获取预约下单数据")
    @GetMapping("/getScheduleInfo/{scheduleId}")
    public ScheduleOrderVo getScheduleOrderVo(
            @PathVariable("scheduleId") String scheduleId) {
        return scheduleService.getScheduleOrderVo(scheduleId);
    }

    @ApiOperation(value = "获取医院签名相关信息")
    @GetMapping("/getSignInfoVo/{hoscode}")
    public SignInfoVo getSignInfoVo(
            @PathVariable("hoscode") String hoscode) {
        return hospitalService.getSignInfoVo(hoscode);
    }
}
